# -*- coding: utf-8 -*-
# @Time    : 2021/11/3 15:46
# @Author  : huangwei
# @File    : client2.py
# @Software: PyCharm
import base64
import time
import requests
import json


def img2str( filepath ):
    with open(filepath, 'rb') as fp:
        # 二进制读取转为base64编码
        img_byte = base64.b64encode(fp.read())

    # 转为str
    byte2str = str(img_byte, encoding='utf-8')
    return byte2str


img_path = 'images/sim.png'
img_str = img2str(img_path)

requests_dict = {'filepath': img_path, 'image': img_str}
request_json = json.dumps(requests_dict, ensure_ascii=False).encode()

t1 = time.time()
response_data = requests.post('http://127.0.0.1:6075/img2excel', data=request_json)
response_json = response_data.json()
print(request_json)
t2 = time.time()
print(t2 - t1)
